# -*- coding:utf-8 -*-

import pandas as pd
from seeting import conget, sqlquery, columns
import time


def getrawdata():
    '''
    :return: 清洗后的数据（返回包括店铺名+店铺编号，订单时刻，几点钟）提取数据的时间。
    '''
    data_raw = pd.read_sql(sqlquery, con=conget)
    time_s = time.strftime ('%Y-%m-%d %H:%M:%S')

    data = data_raw
    data.columns = columns

    # 删除所有包含NULL的数据
    data2 = data_raw.dropna()
    # 重新定义订单类别
    data2.ORDER[data2["ORDER"] == "??外送"] = "外送"
    data2.ORDER[data2["ORDER"] == "专业外送"] = "外送"
    data2.ORDER[data2["ORDER"] == "O"] = "堂食"
    data2.ORDER[data2["ORDER"] == "KIOSK DINE IN"] = "KIOSK"
    data2.ORDER[data2["ORDER"] == "KIOSK TAKEOUT"] = "KIOSK"
    data2.ORDER[data2["ORDER"] == "Kiosk"] = "KIOSK"
    data2.ORDER[data2["ORDER"] == "车道点餐"] = "车道点餐"
    data2.ORDER[data2["ORDER"] == "Pre-Order"] = "PreOrder"
    data2.ORDER[data2["ORDER"] == "Pre-Order_I"] = "PreOrder"
    data2.ORDER[data2["ORDER"] == "Pre-Order_O"] = "PreOrder"
    data2.ORDER[data2["ORDER"] == "I"] = "堂食"
    data2["INFO"] = data2["NAME"] + data2["CODE"]
    data2["TIME"] = pd.to_datetime(data2["TIME"])
    data2["HOUR"] = pd.to_datetime(data2["TIME"]).dt.hour
    data2["AMOUNT"] = pd.to_numeric(data2["AMOUNT"])
    return data2, time_s
